
<template>
  <div class="user-info">
    <!-- 个人信息 -->
    <el-form label-width="220px">
      <!--手机 -->

      <el-form-item label="手机">
        <el-input
          v-model="userInfo.mobile"
          disabled
          style="width:220px"
        />
      </el-form-item>

      <!-- 工号 入职时间 -->

      <el-form-item label="入职时间">
        <el-date-picker
          v-model="userInfo.timeOfEntry"
          type="date"
          class="inputW"
          value-format="yyyy-MM-dd"
        />
      </el-form-item>

      <!-- 员工照片 -->

      <el-form-item label="员工头像">
        <!-- 放置上传图片 -->
        <!-- <img :src="userInfo.staffPhoto"> -->
        <!-- <UploadImg :value="userInfo.staffPhoto" @input=" val=> userInfo.staffPhoto" /> -->
        <UploadImg v-model="userInfo.staffPhoto" />
      </el-form-item>

      <!-- 保存个人信息 -->
      <el-form-item>
        <el-button type="primary" @click="hSave">保存更新</el-button>
        <el-button @click="$router.back()">返回</el-button>
      </el-form-item>
    </el-form>
  </div>
</template>
<script>
import { getUserByIdDetail } from '@/api/user'
import { saveUserDetailById } from '@/api/employees'
export default {
  data() {
    return {
      userId: this.$route.params.id,
      userInfo: {
        mobile: '',
        timeOfEntry: ''
      },
      rules: {
        mobile: [{ required: true, message: '手机号不能为空', trigger: 'blur' }],
        timeOfEntry: [{ required: true, message: '入职时间不能为空', trigger: 'blur' }]
      }
    }
  },
  created() {
    this.loadUserByIdDetail()
  },
  methods: {
    hSave() {
      // 进行兜底校验
      this.$refs.userForm.validate((valid) => {
        // 校验失败
        if (!valid) return
        this.updateUserInfo()
      })
    },
    // 修改员工
    async updateUserInfo() {
      // 假设效验已完成
      try {
        const res = await saveUserDetailById(this.userInfo)
        if (res.data === 10000) {
          this.$message.success('修改成功')
          this.$router.back()
        }
      } catch (err) {
        console.log('err', err)
      }
    },

    async loadUserByIdDetail() {
      console.log('aaaaaaaaaaaa')
      try {
        const res = await getUserByIdDetail(this.userId)
        console.log('getUserByIdDetail', res)
        if (res.code === 10000) {
          this.userInfo = res.data
        }
      } catch (err) {
        this.$message.error(err)
      }
    }
  }
}
</script>

<style scoped lang="scss">
  .user-info{
    padding-top:20px;
  }
</style>
